home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / PRShAttr.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  42.1 KB  |  1,466 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRShAttr.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef PRSHATTR_H
  13. #include "PRShAttr.h"
  14. #endif
  15.  
  16. #ifndef FWGCONST_H
  17. #include "FWGConst.h"
  18. #endif
  19.  
  20. #ifndef FWWINDIB_H
  21. #include "FWWinDIB.h"
  22. #endif
  23.  
  24. #ifndef FWSTREAM_H
  25. #include "FWStream.h"
  26. #endif
  27.  
  28. #ifndef FWMEMHLP_H
  29. #include "FWMemHlp.h"
  30. #endif
  31.  
  32. #ifndef FWCOLOR_H
  33. #include "FWColor.h"
  34. #endif
  35.  
  36. #ifndef FWEXCEPT_H
  37. #include "FWExcept.h"
  38. #endif
  39.  
  40. //========================================================================================
  41. //    CLASS FW_CPrivPatternRep
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment FWGraphics_PrivPatternRep
  46. #endif
  47.  
  48. FW_DEFINE_CLASS_M0(FW_CPrivPatternRep)
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CPrivPatternRep::FW_CPrivPatternRep
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CPrivPatternRep::FW_CPrivPatternRep()
  55. {
  56. }
  57.  
  58. //----------------------------------------------------------------------------------------
  59. //    FW_CPrivPatternRep::~FW_CPrivPatternRep
  60. //----------------------------------------------------------------------------------------
  61.  
  62. FW_CPrivPatternRep::~FW_CPrivPatternRep()
  63. {
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    FW_CPrivPatternRep::Write
  68. //----------------------------------------------------------------------------------------
  69.  
  70. void FW_CPrivPatternRep::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  71. {
  72. FW_UNUSED(type);
  73.     FW_CPrivPatternRep* rep = (FW_CPrivPatternRep*) object;
  74.     rep->Flatten(stream);
  75. }
  76.  
  77. //========================================================================================
  78. //    CLASS FW_CPrivBWPatternRep
  79. //========================================================================================
  80.  
  81. #ifdef FW_BUILD_MAC
  82. #pragma segment FWGraphics_PrivBWPatternRep
  83. #endif
  84.  
  85. FW_DEFINE_AUTO(FW_CPrivBWPatternRep)
  86. FW_DEFINE_CLASS_M1(FW_CPrivBWPatternRep, FW_CPrivPatternRep)
  87.  
  88. const FW_ClassTypeConstant FW_LPrivBWPatternRep = FW_TYPE_CONSTANT('b','w','p','t');
  89. FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivBWPatternRep, FW_CPrivBWPatternRep, FW_CPrivBWPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep()
  96. {
  97. #if defined(__MWERKS__) && GENERATING68K
  98.     unsigned char black[8];
  99.     *(long*)&(black[0]) = 0xFFFFFFFF;
  100.     *(long*)&(black[4]) = 0xFFFFFFFF;
  101. #else
  102.     unsigned char black[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  103. #endif
  104.  
  105.     MoveBitPattern(black, &fBitPattern);
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(const FW_BitPattern& bits)
  114. {
  115.     MoveBitPattern(&bits, &fBitPattern);
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(FW_CReadableStream& stream)
  124. {
  125.     stream.Read(fBitPattern.fData, 8);    
  126.     FW_END_CONSTRUCTOR
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep
  131. //----------------------------------------------------------------------------------------
  132.  
  133. FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep()
  134. {
  135.     FW_START_DESTRUCTOR
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    FW_CPrivBWPatternRep::Invert
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void FW_CPrivBWPatternRep::Invert()
  143. {
  144.     *((long*)&fBitPattern.fData[0]) ^= 0xFFFFFFFFL;
  145.     *((long*)&fBitPattern.fData[4]) ^= 0xFFFFFFFFL;
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    FW_CPrivBWPatternRep::FlipVertically
  150. //----------------------------------------------------------------------------------------
  151.  
  152. void FW_CPrivBWPatternRep::FlipVertically()
  153. {
  154.     for (short i = 0; i<4; i++)
  155.     {
  156.         unsigned char temp = fBitPattern.fData[i];
  157.         fBitPattern.fData[i] = fBitPattern.fData[7-i];
  158.         fBitPattern.fData[7-i] = temp;
  159.     }
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CPrivBWPatternRep::FlipHorizontally
  164. //----------------------------------------------------------------------------------------
  165. // This is not the best implementation
  166.  
  167. void FW_CPrivBWPatternRep::FlipHorizontally()
  168. {    
  169.     for (short j = 0; j<8; j++)
  170.     {
  171.         unsigned char leftMask = 0x80;
  172.         unsigned char rightMask = 0x01;
  173.         unsigned char theChar = fBitPattern.fData[j];
  174.         for (short i = 0; i<4; i++)
  175.         {
  176.             unsigned char left = theChar & leftMask;
  177.             unsigned char right = theChar & rightMask;
  178.             
  179.             if (left)
  180.                 theChar |= rightMask;    // Set
  181.             else
  182.                 theChar ^= right;        // Clear
  183.                 
  184.             if (right)
  185.                 theChar |= leftMask;    // Set
  186.             else
  187.                 theChar ^= left;        // Clear
  188.                 
  189.             leftMask >>= 1;
  190.             rightMask <<= 1;
  191.         }
  192.         fBitPattern.fData[j] = theChar;
  193.     }
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    FW_CPrivBWPatternRep::ShiftRight
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void FW_CPrivBWPatternRep::ShiftRight()
  201. {
  202.     for (short i = 0; i<8; i++)
  203.     {
  204.         unsigned char theChar = fBitPattern.fData[i];
  205.         theChar >>= 1;
  206.         if (fBitPattern.fData[i] & 0x01)
  207.             theChar |= 0x80;
  208.         fBitPattern.fData[i] = theChar;
  209.     }    
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CPrivBWPatternRep::ShiftLeft
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void FW_CPrivBWPatternRep::ShiftLeft()
  217. {
  218.     for (short i = 0; i<8; i++)
  219.     {
  220.         unsigned char theChar = fBitPattern.fData[i];
  221.         theChar <<= 1;
  222.         if (fBitPattern.fData[i] & 0x80)
  223.             theChar |= 0x01;            
  224.         fBitPattern.fData[i] = theChar;
  225.     }    
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    FW_CPrivBWPatternRep::ShiftUp
  230. //----------------------------------------------------------------------------------------
  231.  
  232. void FW_CPrivBWPatternRep::ShiftUp()
  233. {
  234.     unsigned char temp = fBitPattern.fData[0];
  235.     for (short i = 0; i<7; i++)
  236.         fBitPattern.fData[i] = fBitPattern.fData[i+1];
  237.     fBitPattern.fData[7] = temp;
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    FW_CPrivBWPatternRep::ShiftDown
  242. //----------------------------------------------------------------------------------------
  243.  
  244. void FW_CPrivBWPatternRep::ShiftDown()
  245. {
  246.     unsigned char temp = fBitPattern.fData[7];
  247.     for (short i = 7; i>0; i--)
  248.         fBitPattern.fData[i] = fBitPattern.fData[i-1];
  249.     fBitPattern.fData[0] = temp;
  250. }
  251.  
  252. //----------------------------------------------------------------------------------------
  253. //    FW_CPrivBWPatternRep::IsEqual
  254. //----------------------------------------------------------------------------------------
  255.  
  256. FW_Boolean FW_CPrivBWPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
  257. {
  258.     if (other == this)
  259.         return TRUE;
  260.         
  261.     const FW_CPrivBWPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivBWPatternRep, (FW_CPrivPatternRep*)other);
  262.     
  263.     if (patternRep)
  264.     {
  265.         for (short i=0; i<7; i++)
  266.             if (fBitPattern.fData[i] != patternRep->fBitPattern.fData[i])
  267.                 return FALSE;
  268.         return TRUE;
  269.     }
  270.     
  271.     return FALSE;
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    FW_CPrivBWPatternRep::IsBlack
  276. //----------------------------------------------------------------------------------------
  277.  
  278. FW_Boolean FW_CPrivBWPatternRep::IsBlack() const
  279. {
  280.     return fBitPattern.fDataLongs[0] == 0xFFFFFFFFL && fBitPattern.fDataLongs[1] == 0xFFFFFFFFL;
  281. }
  282.  
  283. #ifdef FW_BUILD_WIN
  284. //----------------------------------------------------------------------------------------
  285. //    FW_CPrivBWPatternRep::WinCreatePatternBrush
  286. //----------------------------------------------------------------------------------------
  287.  
  288. HBRUSH FW_CPrivBWPatternRep::WinCreatePatternBrush() const
  289. {
  290.     unsigned char temp[16];    // 16 because rowbytes has to be even
  291.     for (short i=0; i<8; i++)
  292.         temp[2*i] = fBitPattern.fData[i] ^ 0xFF;
  293.         
  294.     HBRUSH hBrush = NULL;
  295.     
  296.     HBITMAP hbmp = ::CreateBitmap(8, 8, 1, 1, temp);
  297.     if(hbmp != NULL)
  298.     {
  299.         hBrush = ::CreatePatternBrush(hbmp);
  300.         ::DeleteObject(hbmp);
  301.     }
  302.     
  303.     return hBrush;
  304. }
  305. #endif
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    FW_CPrivBWPatternRep::Copy
  309. //----------------------------------------------------------------------------------------
  310.  
  311. FW_CPrivPatternRep* FW_CPrivBWPatternRep::Copy() const
  312. {
  313.     return FW_NEW(FW_CPrivBWPatternRep, (fBitPattern));
  314. }
  315.  
  316. #ifdef FW_BUILD_MAC
  317. //----------------------------------------------------------------------------------------
  318. //    FW_CPrivBWPatternRep::MacSetInCurPort
  319. //----------------------------------------------------------------------------------------
  320.  
  321. void FW_CPrivBWPatternRep::MacSetInCurPort() const
  322. {
  323.     ::PenPat((const Pattern*)&fBitPattern);
  324. }
  325. #endif
  326.  
  327. //----------------------------------------------------------------------------------------
  328. //    FW_CPrivBWPatternRep::Flatten
  329. //----------------------------------------------------------------------------------------
  330.  
  331. void FW_CPrivBWPatternRep::Flatten(FW_CWritableStream& stream) const
  332. {
  333.     stream.Write(fBitPattern.fData, 8);
  334. }
  335.  
  336. //----------------------------------------------------------------------------------------
  337. //    FW_CPrivBWPatternRep::Read
  338. //----------------------------------------------------------------------------------------
  339.  
  340. void* FW_CPrivBWPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  341. {
  342. FW_UNUSED(type);
  343.     return FW_NEW(FW_CPrivBWPatternRep, (stream));
  344. }
  345.  
  346. //========================================================================================
  347. //    CLASS FW_CPrivColorPatternRep
  348. //========================================================================================
  349.  
  350. #ifdef FW_BUILD_MAC
  351. #pragma segment FWGraphics_PrivColorPatternRep
  352. #endif
  353.  
  354. FW_DEFINE_AUTO(FW_CPrivColorPatternRep)
  355. FW_DEFINE_CLASS_M1(FW_CPrivColorPatternRep, FW_CPrivPatternRep)
  356.  
  357. const FW_ClassTypeConstant FW_LPrivColorPatternRep = FW_TYPE_CONSTANT('c','o','p','t');
  358. FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivColorPatternRep, FW_CPrivColorPatternRep, FW_CPrivColorPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
  359.  
  360. //----------------------------------------------------------------------------------------
  361. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  362. //----------------------------------------------------------------------------------------
  363.  
  364. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_PlatformColorPattern platformColorPattern) :
  365.     fPlatformColorPattern(platformColorPattern)
  366. {
  367.     FW_ASSERT(fPlatformColorPattern != NULL);
  368.     FW_END_CONSTRUCTOR
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  373. //----------------------------------------------------------------------------------------
  374.  
  375. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_CReadableStream& stream) :
  376.     fPlatformColorPattern(NULL)
  377. {
  378.     // Pattern data
  379.     FW_PixelPattern patData;
  380.     stream.Read(patData.fData, sizeof(patData));
  381.     
  382.     // Color count
  383.     unsigned short nbColors;
  384.     stream >> nbColors;
  385.     
  386.     // Colors
  387.     FW_CColor* colors = new FW_CColor[nbColors];
  388.     FW_TRY
  389.     {
  390.         for(int i = 0; i < nbColors; i ++)
  391.             stream >> colors[i];
  392.  
  393.         // Create the pattern
  394.         MakePixelPattern(patData, nbColors, colors);
  395.     }
  396.     FW_CATCH_BEGIN
  397.     FW_CATCH_EVERYTHING()
  398.     {
  399.         delete[] colors;
  400.         FW_THROW_SAME();
  401.     }
  402.     FW_CATCH_END
  403.     
  404.     // Clean up
  405.     delete[] colors;
  406.     FW_END_CONSTRUCTOR
  407. }
  408.  
  409. //----------------------------------------------------------------------------------------
  410. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  411. //----------------------------------------------------------------------------------------
  412.  
  413. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable) :
  414.     fPlatformColorPattern(NULL)
  415. {
  416. #ifdef FW_BUILD_WIN
  417.     fWinCachedBitmap = NULL;
  418. #endif
  419.     
  420.     MakePixelPattern(pixels, nbColors, colorTable);
  421.     FW_END_CONSTRUCTOR
  422. }
  423.  
  424. //----------------------------------------------------------------------------------------
  425. //    FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep
  426. //----------------------------------------------------------------------------------------
  427.  
  428. FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep()
  429. {
  430.     FW_START_DESTRUCTOR
  431.  
  432. #ifdef FW_BUILD_MAC
  433.     if (fPlatformColorPattern)
  434.         ::DisposePixPat(fPlatformColorPattern);
  435. #endif
  436.  
  437. #ifdef FW_BUILD_WIN
  438.     if (fPlatformColorPattern != NULL)
  439.         FW_DIBFree(fPlatformColorPattern);
  440.         
  441.     WinForgetCachedBitmap();
  442. #endif
  443. }
  444.  
  445. //----------------------------------------------------------------------------------------
  446. //    FW_CPrivColorPatternRep::IsBlack
  447. //----------------------------------------------------------------------------------------
  448.  
  449. FW_Boolean FW_CPrivColorPatternRep::IsBlack() const
  450. {
  451.     return FALSE;
  452. }
  453.  
  454. //----------------------------------------------------------------------------------------
  455. //    FW_CPrivColorPatternRep::IsEqual
  456. //----------------------------------------------------------------------------------------
  457.  
  458. FW_Boolean FW_CPrivColorPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
  459. {
  460.     if (other == this)
  461.         return TRUE;
  462.  
  463.     const FW_CPrivColorPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivColorPatternRep, (FW_CPrivPatternRep*)other);
  464.     if (patternRep == NULL)
  465.         return FALSE;
  466.  
  467.     // Compare the pixels        
  468.     FW_PixelPattern pixData1;
  469.     GetPixelData(pixData1);
  470.  
  471.     FW_PixelPattern pixData2;
  472.     patternRep->GetPixelData(pixData2);
  473.     
  474.     if(::memcmp(pixData1.fData, pixData2.fData, sizeof(FW_PixelPattern)) != 0)
  475.         return FALSE;
  476.     
  477.     // Compare the color tables
  478.     FW_SColor* colors1 = NULL;
  479.     unsigned short nbColors1 = GetColorTable(colors1);
  480.  
  481.     FW_SColor* colors2 = NULL;
  482.     unsigned short nbColors2 = patternRep->GetColorTable(colors2);
  483.         
  484.     if(nbColors1 != nbColors2 || ::memcmp(colors1, colors2, sizeof(FW_SColor) * nbColors1) != 0)
  485.     {
  486.         delete[] colors1;
  487.         delete[] colors2;
  488.         return FALSE;
  489.     }
  490.  
  491.     return TRUE;
  492. }
  493.  
  494. //----------------------------------------------------------------------------------------
  495. //    FW_CPrivColorPatternRep::Copy
  496. //----------------------------------------------------------------------------------------
  497.  
  498. FW_CPrivPatternRep* FW_CPrivColorPatternRep::Copy() const
  499. {
  500.     FW_PlatformColorPattern platformColorPattern;
  501.     
  502. #ifdef FW_BUILD_MAC
  503.     platformColorPattern = ::NewPixPat();
  504.     ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  505. #endif
  506.  
  507. #ifdef FW_BUILD_WIN
  508.     platformColorPattern = FW_DIBCreateCopy(fPlatformColorPattern);
  509. #endif
  510.  
  511.     return FW_NEW(FW_CPrivColorPatternRep, (platformColorPattern));
  512. }
  513.  
  514. //----------------------------------------------------------------------------------------
  515. //    FW_CPrivColorPatternRep::Flatten
  516. //----------------------------------------------------------------------------------------
  517.  
  518. void FW_CPrivColorPatternRep::Flatten(FW_CWritableStream& stream) const
  519. {
  520.     // Pixel data
  521.     FW_PixelPattern pixData;
  522.     GetPixelData(pixData);
  523.     stream.Write(pixData.fData, sizeof(pixData));
  524.     
  525.     // ----- Colors
  526.     FW_SColor* colors = NULL;
  527.     unsigned short nbColors = GetColorTable(colors);
  528.     FW_TRY
  529.     {
  530.         stream << nbColors;
  531.         for(int i = 0; i < nbColors; i++)
  532.             stream << FW_CColor(colors[i]);    // [HLX] added the cast
  533.     }
  534.     FW_CATCH_BEGIN
  535.     FW_CATCH_EVERYTHING()
  536.     {
  537.         // Clean up
  538.         delete[] colors;
  539.  
  540.         FW_THROW_SAME();
  541.     }
  542.     FW_CATCH_END
  543.     
  544.     // Clean up
  545.     delete[] colors;
  546. }
  547.  
  548. //----------------------------------------------------------------------------------------
  549. //    FW_CPrivColorPatternRep::Invert
  550. //----------------------------------------------------------------------------------------
  551.  
  552. void FW_CPrivColorPatternRep::Invert()
  553. {
  554.     // Get current pattern info
  555.     FW_PixelPattern pixData;
  556.     GetPixelData(pixData);
  557.  
  558.     // ----- Look for minimum and maximun -----
  559.     unsigned char max = 0x00;
  560.     int i;
  561.     
  562.     for (i = 0; i < 8 * 8; i++)
  563.     {
  564.         unsigned char c = pixData.fDataRaw[i];
  565.         if (c > max)
  566.             max = c;            
  567.     }
  568.  
  569.     // ----- Invert it -----
  570.     for (i = 0; i < 8 * 8; i++)
  571.         pixData.fDataRaw[i] = max - pixData.fDataRaw[i];
  572.  
  573.     // Update the pattern
  574.     SetPixelData(pixData);
  575. }
  576.  
  577. //----------------------------------------------------------------------------------------
  578. //    FW_CPrivColorPatternRep::FlipVertically
  579. //----------------------------------------------------------------------------------------
  580.  
  581. void FW_CPrivColorPatternRep::FlipVertically()
  582. {
  583.     // Get current pattern info
  584.     FW_PixelPattern pixData;
  585.     GetPixelData(pixData);
  586.     
  587.     // Flip it
  588.     for (short i = 0; i < 4; i++)
  589.         for (short j = 0; j < 2; j++)
  590.         {
  591.             unsigned long l = pixData.fDataLongs[i][j];
  592.             pixData.fDataLongs[i][j] = pixData.fDataLongs[7 - i][j];
  593.             pixData.fDataLongs[7 - i][j] = l;
  594.         }
  595.  
  596.     // Update the pattern
  597.     SetPixelData(pixData);
  598. }
  599.  
  600. //----------------------------------------------------------------------------------------
  601. //    FW_CPrivColorPatternRep::FlipHorizontally
  602. //----------------------------------------------------------------------------------------
  603.  
  604. void FW_CPrivColorPatternRep::FlipHorizontally()
  605. {    
  606.     // Get current pattern info
  607.     FW_PixelPattern pixData;
  608.     GetPixelData(pixData);
  609.     
  610.     // Flip it
  611.     for (short i = 0; i < 8; i++)
  612.         for (short j = 0; j < 4; j++)
  613.         {
  614.             unsigned char c = pixData.fData[i][j];
  615.             pixData.fData[i][j] = pixData.fData[i][7 - j];
  616.             pixData.fData[i][7 - j] = c;
  617.         }
  618.  
  619.     // Update the pattern
  620.     SetPixelData(pixData);
  621. }
  622.  
  623. //----------------------------------------------------------------------------------------
  624. //    FW_CPrivColorPatternRep::ShiftRight
  625. //----------------------------------------------------------------------------------------
  626.  
  627. void FW_CPrivColorPatternRep::ShiftRight()
  628. {
  629.     // Get current pattern info
  630.     FW_PixelPattern pixData;
  631.     GetPixelData(pixData);
  632.  
  633.     // Shift it
  634.     for (short i = 0; i < 8; i++)
  635.     {
  636.         unsigned char c = pixData.fData[i][7];
  637.         for(short j = 7; j > 0; j--)
  638.             pixData.fData[i][j] = pixData.fData[i][j - 1];
  639.         pixData.fData[i][0] = c;
  640.     }
  641.  
  642.     // Update the pattern
  643.     SetPixelData(pixData);
  644. }
  645.  
  646. //----------------------------------------------------------------------------------------
  647. //    FW_CPrivColorPatternRep::ShiftLeft
  648. //----------------------------------------------------------------------------------------
  649.  
  650. void FW_CPrivColorPatternRep::ShiftLeft()
  651. {
  652.     // Get current pattern info
  653.     FW_PixelPattern pixData;
  654.     GetPixelData(pixData);
  655.     
  656.     // Shift it
  657.     for (short i = 0; i < 8; i++)
  658.     {
  659.         unsigned char c = pixData.fData[i][0];
  660.         for(short j = 0; j < 7; j++)
  661.             pixData.fData[i][j] = pixData.fData[i][j + 1];
  662.         pixData.fData[i][7] = c;
  663.     }
  664.  
  665.     // Update the pattern
  666.     SetPixelData(pixData);
  667. }
  668.  
  669. //----------------------------------------------------------------------------------------
  670. //    FW_CPrivColorPatternRep::ShiftUp
  671. //----------------------------------------------------------------------------------------
  672.  
  673. void FW_CPrivColorPatternRep::ShiftUp()
  674. {
  675.     // Get current pattern info
  676.     FW_PixelPattern pixData;
  677.     GetPixelData(pixData);
  678.     
  679.     // Shift it
  680.     unsigned long temp0 = pixData.fDataLongs[0][0];
  681.     unsigned long temp1 = pixData.fDataLongs[0][1];
  682.     
  683.     for (short i = 0; i < 7; i++)
  684.     {
  685.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i + 1][0];
  686.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i + 1][1];
  687.     }
  688.         
  689.     pixData.fDataLongs[7][0] = temp0;
  690.     pixData.fDataLongs[7][1] = temp1;
  691.  
  692.     // Update the pattern
  693.     SetPixelData(pixData);
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //    FW_CPrivColorPatternRep::ShiftDown
  698. //----------------------------------------------------------------------------------------
  699.  
  700. void FW_CPrivColorPatternRep::ShiftDown()
  701. {
  702.     // Get current pattern info
  703.     FW_PixelPattern pixData;
  704.     GetPixelData(pixData);
  705.     
  706.     // Shift it
  707.     unsigned long temp0 = pixData.fDataLongs[7][0];
  708.     unsigned long temp1 = pixData.fDataLongs[7][1];
  709.     
  710.     for (short i = 7; i > 0; i--)
  711.     {
  712.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i - 1][0];
  713.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i - 1][1];
  714.     }
  715.  
  716.     pixData.fDataLongs[0][0] = temp0;
  717.     pixData.fDataLongs[0][1] = temp1;
  718.  
  719.     // Update the pattern
  720.     SetPixelData(pixData);
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. //    FW_CPrivColorPatternRep::Read
  725. //----------------------------------------------------------------------------------------
  726.  
  727. void* FW_CPrivColorPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  728. {
  729. FW_UNUSED(type);
  730.     return FW_NEW(FW_CPrivColorPatternRep, (stream));
  731. }
  732.  
  733. #ifdef FW_BUILD_MAC
  734. //----------------------------------------------------------------------------------------
  735. //    FW_CPrivColorPatternRep::MacSetInCurPort
  736. //----------------------------------------------------------------------------------------
  737.  
  738. void FW_CPrivColorPatternRep::MacSetInCurPort() const
  739. {
  740.     FW_ASSERT(fPlatformColorPattern != NULL);
  741.  
  742. //    FW_PlatformColorPattern platformColorPattern = ::NewPixPat();
  743. //    ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  744. //    ::PenPixPat(platformColorPattern);
  745.     // [HLX] We should not have to make a copy. Quickdraw won't dispose it. If we dispose it
  746.     // Quickdraw will reset the 'standard pattern'
  747.     ::PenPixPat(fPlatformColorPattern);
  748. }
  749. #endif
  750.  
  751. #ifdef FW_BUILD_WIN
  752. //----------------------------------------------------------------------------------------
  753. //    FW_CPrivColorPatternRep::WinCreatePatternBrush
  754. //----------------------------------------------------------------------------------------
  755.  
  756. HBRUSH FW_CPrivColorPatternRep::WinCreatePatternBrush() const
  757. {
  758.     HBRUSH hBrush = NULL;
  759.  
  760.     // Convert into a DDB for effeciency
  761.     if (fWinCachedBitmap == NULL)
  762.         ((FW_CPrivColorPatternRep*) this)->fWinCachedBitmap = FW_DIBConvertToBitmap(fPlatformColorPattern, NULL);
  763.  
  764.     // Create the brush
  765.     if(fWinCachedBitmap != NULL)
  766.         hBrush = ::CreatePatternBrush(fWinCachedBitmap);
  767.  
  768.     return hBrush;
  769. }
  770. #endif
  771.  
  772. #ifdef FW_BUILD_WIN
  773. //----------------------------------------------------------------------------------------
  774. //    FW_CPrivColorPatternRep::WinForgetCachedBitmap
  775. //----------------------------------------------------------------------------------------
  776.  
  777. void FW_CPrivColorPatternRep::WinForgetCachedBitmap()
  778. {
  779.     if (fWinCachedBitmap != NULL)
  780.     {
  781.         ::DeleteObject(fWinCachedBitmap);
  782.         fWinCachedBitmap = NULL;
  783.     }
  784. }
  785. #endif
  786.  
  787. #ifdef FW_BUILD_MAC
  788. //----------------------------------------------------------------------------------------
  789. //    FW_CPrivColorPatternRep::MacNewPixPat
  790. //----------------------------------------------------------------------------------------
  791.  
  792. PixPatHandle FW_CPrivColorPatternRep::MacNewPixPat(const void* pixels, 
  793.                                                 short rowBytes, short pixelSize,
  794.                                                 short withPower, short heightPower,
  795.                                                 short nbColors, const FW_SColor* colorTable)
  796. {
  797.     FW_ASSERT(pixels != NULL);
  798.     FW_ASSERT(colorTable != NULL);
  799.     FW_ASSERT((rowBytes & 0x0001) == 0);
  800.     FW_ASSERT(pixelSize == 1 || pixelSize == 2 || pixelSize == 4 || pixelSize == 8);
  801.     FW_ASSERT(withPower != 0);
  802.     FW_ASSERT(heightPower != 0);
  803.     FW_ASSERT(nbColors <= (1 << pixelSize));
  804.  
  805.     PixPatHandle pixPat = ::NewPixPat();
  806.     
  807.     (*pixPat)->patType = 1;
  808.         
  809.     // ----- Creates the pixMap -----
  810.     PixMapHandle pixMap = (*pixPat)->patMap;
  811.     
  812.     (*pixMap)->rowBytes = rowBytes | 0x8000;
  813.     (*pixMap)->bounds.left = 0;
  814.     (*pixMap)->bounds.top = 0;
  815.     (*pixMap)->bounds.right = 1 << withPower;
  816.     (*pixMap)->bounds.bottom = 1 << heightPower;
  817.     (*pixMap)->pixelSize = pixelSize;
  818.     (*pixMap)->cmpCount = 1;
  819.     (*pixMap)->cmpSize = pixelSize;
  820.     
  821.     // ----- Set up the color table -----
  822.     CTabHandle hColors = (*pixMap)->pmTable;    
  823.     Size colorTabSize = sizeof(ColorTable) + (nbColors * sizeof(ColorSpec));    
  824.     ::SetHandleSize((Handle)hColors, colorTabSize);
  825.     
  826.     ::HLock((Handle)hColors);
  827.     CTabPtr pColors = *hColors;
  828.     pColors->ctSeed = ::GetCTSeed();
  829.     pColors->ctFlags = 0;
  830.     pColors->ctSize = nbColors - 1;
  831.     
  832.     for (short i = 0; i<nbColors; i++)
  833.     {
  834.         pColors->ctTable[i].value = i;
  835.         FW_MacColorToRGB(colorTable[i], &pColors->ctTable[i].rgb);
  836.     }
  837.     ::HUnlock((Handle)hColors);
  838.     
  839.     // ----- Creates the pattern data -----
  840.     Size dataSize = (Size)rowBytes * 8;
  841.     Handle patData = (*pixPat)->patData;
  842.     ::SetHandleSize(patData, dataSize);
  843.         
  844.     ::HLock(patData);
  845.     ::BlockMove(pixels, *patData, dataSize);
  846.     ::HUnlock(patData);
  847.     
  848.     return pixPat;
  849. }
  850. #endif
  851.  
  852. #ifdef FW_BUILD_WIN
  853.  
  854. //----------------------------------------------------------------------------------------
  855. //    FW_CPrivColorPatternRep::WinFlipPixelCopy
  856. //----------------------------------------------------------------------------------------
  857.  
  858. void FW_CPrivColorPatternRep::WinFlipPixelCopy(const void* source, void* dest)
  859. {
  860.     unsigned long* sourceL = (unsigned long*) source;
  861.     unsigned long* destL = (unsigned long*) dest;
  862.     
  863.     for(int i = 0; i < 16; i += 2)
  864.     {
  865.         destL[14 - i] = sourceL[i];
  866.         destL[15 - i] = sourceL[i + 1];
  867.     }
  868. }
  869.  
  870. #endif
  871.  
  872. //----------------------------------------------------------------------------------------
  873. //    FW_CPrivColorPatternRep::MakePixelPattern
  874. //----------------------------------------------------------------------------------------
  875.  
  876. void FW_CPrivColorPatternRep::MakePixelPattern(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable)
  877. {
  878. #ifdef FW_BUILD_MAC
  879.     fPlatformColorPattern = MacNewPixPat(pixels.fData, 8, 8, 3, 3, nbColors, colorTable);
  880. #endif
  881.  
  882. #ifdef FW_BUILD_WIN
  883.     // We need to flip the bits because DIBs are stored bottom-to-top
  884.     FW_PixelPattern pixData;
  885.     WinFlipPixelCopy(pixels.fData, pixData.fData);
  886.     
  887.     // Create the DIB
  888.     fPlatformColorPattern = FW_DIBCreate(8, 8, 8, nbColors, colorTable, pixData.fData);
  889. #endif
  890. }
  891.  
  892. //----------------------------------------------------------------------------------------
  893. //    FW_CPrivColorPatternRep::GetPixelData
  894. //----------------------------------------------------------------------------------------
  895.  
  896. void FW_CPrivColorPatternRep::GetPixelData(FW_PixelPattern& pixData) const
  897. {
  898. #ifdef FW_BUILD_MAC
  899.     Handle patData = (*fPlatformColorPattern)->patData;
  900.  
  901.     ::HLock(patData);
  902.     BlockMove((FW_PixelPattern*)*patData, pixData.fDataRaw, 64);
  903.     ::HUnlock(patData);
  904. #endif
  905. #ifdef FW_BUILD_WIN
  906.     FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
  907.     WinFlipPixelCopy(pixels, pixData.fData);
  908. #endif
  909. }
  910.  
  911. //----------------------------------------------------------------------------------------
  912. //    FW_CPrivColorPatternRep::SetPixelData
  913. //----------------------------------------------------------------------------------------
  914.  
  915. void FW_CPrivColorPatternRep::SetPixelData(const FW_PixelPattern& pixData)
  916. {
  917. #ifdef FW_BUILD_MAC
  918.     Handle patData = (*fPlatformColorPattern)->patData;
  919.  
  920.     ::HLock(patData);
  921.     ::BlockMove(pixData.fDataRaw, (FW_PixelPattern*)*patData, 64);
  922.     ::HUnlock(patData);
  923.  
  924.     ::PixPatChanged(fPlatformColorPattern);
  925. #endif
  926. #ifdef FW_BUILD_WIN
  927.     FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
  928.     WinFlipPixelCopy(pixData.fData, pixels);
  929.  
  930.     WinForgetCachedBitmap();
  931. #endif
  932. }
  933.  
  934. //----------------------------------------------------------------------------------------
  935. //    FW_CPrivColorPatternRep::GetColorTable
  936. //----------------------------------------------------------------------------------------
  937.  
  938. unsigned short FW_CPrivColorPatternRep::GetColorTable(FW_SColor*& colors) const
  939. {
  940. #ifdef FW_BUILD_MAC
  941.     PixMapHandle pixMap = (*fPlatformColorPattern)->patMap;
  942.  
  943.     CTabHandle hColors = (*pixMap)->pmTable;    
  944.     FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)hColors);
  945.     CTabPtr pColors = *hColors;
  946.  
  947.     unsigned short nbColors = pColors->ctSize + 1;
  948.     colors = new FW_SColor[nbColors];
  949.     for (unsigned short i = 0; i<nbColors; i++)
  950.         colors[i] = FW_MacRGBToColor(&pColors->ctTable[i].rgb);
  951.  
  952.     return nbColors;
  953. #endif
  954. #ifdef FW_BUILD_WIN
  955.     FW_SColor* rgbColors = NULL;
  956.     unsigned short nColors = FW_DIBAcquireColorTable(fPlatformColorPattern, &rgbColors);
  957.     
  958.     // Convert RGB colors to C++ colors
  959.     colors = new FW_SColor[nColors];
  960.     for (unsigned short i = 0; i < nColors; ++ i)
  961.         colors[i] = rgbColors[i];
  962.         
  963.     FW_DIBReleaseColorTable(rgbColors);
  964.     
  965.     return nColors;
  966. #endif
  967. }
  968.  
  969. //========================================================================================
  970. //    class FW_CPrivInkRep
  971. //========================================================================================
  972.  
  973. #ifdef FW_BUILD_MAC
  974. #pragma segment FWGraphics_PrivInkRep
  975. #endif
  976.  
  977. //----------------------------------------------------------------------------------------
  978. //    FW_CPrivInkRep::FW_CPrivInkRep
  979. //----------------------------------------------------------------------------------------
  980.  
  981. FW_CPrivInkRep::FW_CPrivInkRep(FW_SColor fore, FW_SColor back, FW_TransferModes mode):
  982.     fForeColor(fore),
  983.     fBackColor(back),
  984.     fTransferMode(mode)
  985. {
  986. }
  987.  
  988. //----------------------------------------------------------------------------------------
  989. //    FW_CPrivInkRep::FW_CPrivInkRep
  990. //----------------------------------------------------------------------------------------
  991.  
  992. FW_CPrivInkRep::FW_CPrivInkRep(FW_EStandardInks std) :
  993.     fForeColor(FW_kRGBBlack),
  994.     fBackColor(FW_kRGBWhite)
  995. {
  996.     switch (std)
  997.     {
  998.     default:
  999.     case FW_kNormalInk:
  1000.         fTransferMode = FW_kCopy;
  1001.         break;
  1002.  
  1003.     case FW_kNormalTextInk:
  1004.         fTransferMode = FW_kOr;
  1005.         break;
  1006.  
  1007.     case FW_kInvertInk:
  1008.         fTransferMode = FW_kInvert;
  1009.         break;
  1010.  
  1011.     case FW_kWhiteEraseInk:
  1012.         fTransferMode = FW_kErase;
  1013.         break;
  1014.     }
  1015. }
  1016.  
  1017. //----------------------------------------------------------------------------------------
  1018. //    FW_CPrivInkRep::FW_CPrivInkRep
  1019. //----------------------------------------------------------------------------------------
  1020.  
  1021. FW_CPrivInkRep::FW_CPrivInkRep(const FW_CPrivInkRep& otherRep):
  1022.     fForeColor(otherRep.fForeColor),
  1023.     fBackColor(otherRep.fBackColor),
  1024.     fTransferMode(otherRep.fTransferMode)
  1025. {
  1026. }
  1027.  
  1028. //----------------------------------------------------------------------------------------
  1029. //    FW_CPrivInkRep::FW_CPrivInkRep
  1030. //----------------------------------------------------------------------------------------
  1031.  
  1032. FW_CPrivInkRep::FW_CPrivInkRep(FW_CReadableStream& stream)
  1033. {
  1034.     stream >> fForeColor;
  1035.     stream >> fBackColor;
  1036.     stream >> fTransferMode;
  1037. }
  1038.  
  1039. //----------------------------------------------------------------------------------------
  1040. //    FW_CPrivInkRep::~FW_CPrivInkRep
  1041. //----------------------------------------------------------------------------------------
  1042.  
  1043. FW_CPrivInkRep::~FW_CPrivInkRep()
  1044. {
  1045. }
  1046.  
  1047. //----------------------------------------------------------------------------------------
  1048. //    FW_CPrivInkRep::IsEqual
  1049. //----------------------------------------------------------------------------------------
  1050.  
  1051. FW_Boolean FW_CPrivInkRep::IsEqual(const FW_CPrivInkRep* other) const
  1052. {
  1053.     if (other == this)
  1054.         return TRUE;
  1055.  
  1056.     return    fTransferMode == other->fTransferMode &&
  1057.             fForeColor == other->fForeColor && 
  1058.             fBackColor == other->fBackColor;
  1059. }
  1060.  
  1061. //----------------------------------------------------------------------------------------
  1062. //    FW_CPrivInkRep::Write
  1063. //----------------------------------------------------------------------------------------
  1064.  
  1065. void FW_CPrivInkRep::Write(FW_CWritableStream& stream) const
  1066. {
  1067.     stream << fForeColor;
  1068.     stream << fBackColor;
  1069.     stream << fTransferMode;
  1070. }
  1071.  
  1072. //========================================================================================
  1073. //    class FW_CPrivStyleRep
  1074. //========================================================================================
  1075.  
  1076. FW_DEFINE_AUTO(FW_CPrivStyleRep)
  1077.  
  1078. //----------------------------------------------------------------------------------------
  1079. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1080. //----------------------------------------------------------------------------------------
  1081.  
  1082. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_EStyleDash dash) :
  1083.     fPenSize(penSize),
  1084.     fDash(dash),
  1085.     fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
  1086. {
  1087.     FW_END_CONSTRUCTOR
  1088. }
  1089.  
  1090. //----------------------------------------------------------------------------------------
  1091. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1092. //----------------------------------------------------------------------------------------
  1093.  
  1094. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_HPattern pattern) :
  1095.     fPenSize(penSize),
  1096.     fDash(FW_kSolidLine),
  1097.     fPattern(pattern)
  1098. {
  1099.     FW_END_CONSTRUCTOR
  1100. }
  1101.  
  1102. //----------------------------------------------------------------------------------------
  1103. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1104. //----------------------------------------------------------------------------------------
  1105.  
  1106. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_CReadableStream& stream)
  1107. {
  1108.     stream >> fPenSize;
  1109.     
  1110.     short nDash;
  1111.     stream >> nDash;
  1112.     fDash = (FW_EStyleDash) nDash;
  1113.     
  1114.     FW_CPrivPatternRep* pattern;
  1115.     FW_READ_DYNAMIC_OBJECT(stream, &pattern, FW_CPrivPatternRep);
  1116.     fPattern = pattern;
  1117.  
  1118.     FW_END_CONSTRUCTOR
  1119. }
  1120.  
  1121. //----------------------------------------------------------------------------------------
  1122. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1123. //----------------------------------------------------------------------------------------
  1124.  
  1125. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_EStandardStyles std) :
  1126.     fPenSize(FW_IntToFixed(0)),
  1127.     fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
  1128. {
  1129.     switch(std)
  1130.     {
  1131.     default:
  1132.         FW_ASSERT(FALSE);        // Invalid standard style
  1133.                                 // fall-through
  1134.     case FW_kNormalStyle:
  1135.         fDash = FW_kSolidLine;
  1136.         break;
  1137.  
  1138.     case FW_kDashStyle:
  1139.         fDash = FW_kDash;
  1140.         break;
  1141.  
  1142.     case FW_kDotStyle:
  1143.         fDash = FW_kDot;
  1144.         break;
  1145.  
  1146.     case FW_kDashDotStyle:
  1147.         fDash = FW_kDashDot;
  1148.         break;
  1149.  
  1150.     case FW_kDashDotDotStyle:
  1151.         fDash = FW_kDashDotDot;
  1152.         break;
  1153.     }
  1154.  
  1155.     FW_END_CONSTRUCTOR
  1156. }
  1157.  
  1158. //----------------------------------------------------------------------------------------
  1159. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1160. //----------------------------------------------------------------------------------------
  1161.  
  1162. FW_CPrivStyleRep::FW_CPrivStyleRep(const FW_CPrivStyleRep& otherRep) :
  1163.     fPenSize (otherRep.fPenSize),
  1164.     fDash    (otherRep.fDash),
  1165.     fPattern (otherRep.fPattern)
  1166. {
  1167.     FW_END_CONSTRUCTOR
  1168. }
  1169.  
  1170. //----------------------------------------------------------------------------------------
  1171. //    FW_CPrivStyleRep::~FW_CPrivStyleRep
  1172. //----------------------------------------------------------------------------------------
  1173.  
  1174. FW_CPrivStyleRep::~FW_CPrivStyleRep()
  1175. {    
  1176.     FW_START_DESTRUCTOR
  1177. }
  1178.  
  1179. //----------------------------------------------------------------------------------------
  1180. //    FW_CPrivStyleRep::GetUnSharedPattern
  1181. //----------------------------------------------------------------------------------------
  1182.  
  1183. FW_HPattern FW_CPrivStyleRep::GetUnSharedPattern()
  1184. {
  1185.     if (fPattern->GetRefCount() > 1)
  1186.         fPattern = fPattern->Copy();
  1187.  
  1188.     return fPattern;
  1189. }
  1190.  
  1191. //----------------------------------------------------------------------------------------
  1192. //    FW_CPrivStyleRep::Write
  1193. //----------------------------------------------------------------------------------------
  1194.  
  1195. void FW_CPrivStyleRep::Write(FW_CWritableStream& stream) const
  1196. {
  1197.     stream << fPenSize;
  1198.     stream << (short) fDash;
  1199.     
  1200.     const FW_CPrivPatternRep* rep = fPattern;
  1201.     FW_WRITE_DYNAMIC_OBJECT(stream, rep, FW_CPrivPatternRep);
  1202. }
  1203.  
  1204. //----------------------------------------------------------------------------------------
  1205. //    FW_CPrivStyleRep::IsEqual
  1206. //----------------------------------------------------------------------------------------
  1207.  
  1208. FW_Boolean FW_CPrivStyleRep::IsEqual(const FW_CPrivStyleRep* other) const
  1209. {
  1210.     if (other == this)
  1211.         return TRUE;
  1212.         
  1213.     return fPenSize == other->fPenSize &&
  1214.             fDash == other->fDash &&
  1215.             fPattern->IsEqual(other->fPattern);
  1216. }
  1217.  
  1218. //========================================================================================
  1219. //    class FW_CPrivFontRep
  1220. //========================================================================================
  1221.  
  1222. FW_DEFINE_AUTO(FW_CPrivFontRep)
  1223.  
  1224. //----------------------------------------------------------------------------------------
  1225. //    FW_CPrivFontRep::FW_CPrivFontRep
  1226. //----------------------------------------------------------------------------------------
  1227.  
  1228. FW_CPrivFontRep::FW_CPrivFontRep() :
  1229.     fFontStyle(FW_kPlain),
  1230.     fFontSize(FW_IntToFixed(12)),
  1231.     fFontName()
  1232. #ifdef FW_BUILD_MAC
  1233.     ,fMacValidCache(FALSE)
  1234. #endif
  1235. {
  1236.     FW_END_CONSTRUCTOR
  1237. }
  1238.  
  1239. //----------------------------------------------------------------------------------------
  1240. //    FW_CPrivFontRep::FW_CPrivFontRep
  1241. //----------------------------------------------------------------------------------------
  1242.  
  1243. FW_CPrivFontRep::FW_CPrivFontRep(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize) :
  1244.     fFontStyle(fontStyle),
  1245.     fFontSize(fontSize),
  1246.     fFontName(fontName)
  1247. #ifdef FW_BUILD_MAC
  1248.     ,fMacValidCache(FALSE)
  1249. #endif
  1250. {
  1251.     FW_END_CONSTRUCTOR
  1252. }
  1253.  
  1254. //----------------------------------------------------------------------------------------
  1255. //    FW_CPrivFontRep::FW_CPrivFontRep
  1256. //----------------------------------------------------------------------------------------
  1257.  
  1258. FW_CPrivFontRep::FW_CPrivFontRep(const FW_CPrivFontRep& otherRep):
  1259.     fFontStyle(otherRep.fFontStyle),
  1260.     fFontSize(otherRep.fFontSize),
  1261.     fFontName(otherRep.fFontName)
  1262. #ifdef FW_BUILD_MAC
  1263.     ,fMacValidCache(FALSE)
  1264. #endif
  1265. {
  1266.     FW_END_CONSTRUCTOR
  1267. }
  1268.  
  1269. //----------------------------------------------------------------------------------------
  1270. //    FW_CPrivFontRep::FW_CPrivFontRep
  1271. //----------------------------------------------------------------------------------------
  1272.  
  1273. FW_CPrivFontRep::FW_CPrivFontRep(FW_CReadableStream& stream)
  1274. #ifdef FW_BUILD_MAC
  1275.     : fMacValidCache(FALSE)
  1276. #endif
  1277. {
  1278.     stream >> fFontSize;
  1279.     stream >> fFontStyle;
  1280.     stream >> fFontName;
  1281.     FW_END_CONSTRUCTOR
  1282. }
  1283.  
  1284. //----------------------------------------------------------------------------------------
  1285. //    FW_CPrivFontRep::FW_CPrivFontRep
  1286. //----------------------------------------------------------------------------------------
  1287.  
  1288. FW_CPrivFontRep::FW_CPrivFontRep(FW_EStandardFonts std) :
  1289.     fFontSize(FW_IntToFixed(12)),
  1290.     fFontStyle(FW_kPlain)
  1291. #ifdef FW_BUILD_MAC
  1292.     , fMacValidCache(FALSE)
  1293. #endif
  1294. {
  1295.     switch (std) 
  1296.     {
  1297.         case FW_kNormalFont:
  1298.             fFontName = FW_kDefaultFont;
  1299.             break;
  1300.         case FW_kSystemFont12:
  1301.             fFontName = FW_kSystemFont;
  1302.             break;
  1303.         case FW_kHelvetica12:
  1304.             fFontName = FW_kHelvetica;
  1305.             break;
  1306.         case FW_kTimes12:
  1307.             fFontName = FW_kTimes;
  1308.             break;
  1309.         case FW_kPalatino12:
  1310.             fFontName = FW_kPalatino;
  1311.             break;
  1312.         case FW_kCourier12:
  1313.             fFontName = FW_kCourier;
  1314.             break;            
  1315.     }
  1316.     FW_END_CONSTRUCTOR
  1317. }
  1318.     
  1319. //----------------------------------------------------------------------------------------
  1320. //    FW_CPrivFontRep::~FW_CPrivFontRep
  1321. //----------------------------------------------------------------------------------------
  1322.  
  1323. FW_CPrivFontRep::~FW_CPrivFontRep()
  1324. {
  1325.     FW_START_DESTRUCTOR
  1326. }
  1327.  
  1328. //----------------------------------------------------------------------------------------
  1329. //    FW_CPrivFontRep::SetFontName
  1330. //----------------------------------------------------------------------------------------
  1331.  
  1332. void FW_CPrivFontRep::SetFontName(const FW_CString& fontName)
  1333. {
  1334.     fFontName = fontName;
  1335. #ifdef FW_BUILD_MAC
  1336.     fMacValidCache = FALSE;
  1337. #endif
  1338. }
  1339.  
  1340. //----------------------------------------------------------------------------------------
  1341. //    FW_CPrivFontRep::SetFontStyle
  1342. //----------------------------------------------------------------------------------------
  1343.  
  1344. void FW_CPrivFontRep::SetFontStyle(FW_FontStyle fontStyle)
  1345. {
  1346.     fFontStyle = fontStyle;
  1347. #ifdef FW_BUILD_MAC
  1348.     fMacValidCache = FALSE;
  1349. #endif
  1350. }
  1351.  
  1352. //----------------------------------------------------------------------------------------
  1353. //    FW_CPrivFontRep::Write
  1354. //----------------------------------------------------------------------------------------
  1355.  
  1356. void FW_CPrivFontRep::Write(FW_CWritableStream& stream) const
  1357. {
  1358.     stream << fFontSize;
  1359.     stream << fFontStyle;
  1360.     stream << fFontName;
  1361. }
  1362.  
  1363. #ifdef FW_BUILD_MAC
  1364. //----------------------------------------------------------------------------------------
  1365. //    FW_CPrivFontRep::MacGetFontID
  1366. //----------------------------------------------------------------------------------------
  1367.  
  1368. short FW_CPrivFontRep::MacGetFontID() const
  1369. {
  1370.     ((FW_CPrivFontRep*)this)->MacCheckFontCache();
  1371.     return fMacFontID;
  1372. }
  1373. #endif
  1374.  
  1375. #ifdef FW_BUILD_MAC
  1376. //----------------------------------------------------------------------------------------
  1377. //    FW_CPrivFontRep::MacGetFontStyle
  1378. //----------------------------------------------------------------------------------------
  1379.  
  1380. Style FW_CPrivFontRep::MacGetFontStyle() const
  1381. {
  1382.     ((FW_CPrivFontRep*)this)->MacCheckFontCache();
  1383.     return fMacFontStyle;
  1384. }
  1385. #endif
  1386.  
  1387. #ifdef FW_BUILD_MAC
  1388. //----------------------------------------------------------------------------------------
  1389. //    FW_CPrivFontRep::MacCheckFontCache
  1390. //----------------------------------------------------------------------------------------
  1391.  
  1392. void FW_CPrivFontRep::MacCheckFontCache()
  1393. {
  1394.     if (!fMacValidCache)
  1395.     {
  1396.         fMacFontStyle = normal;
  1397.         if (fFontStyle & FW_kBold)
  1398.             fMacFontStyle += bold;
  1399.         if (fFontStyle & FW_kItalic)
  1400.             fMacFontStyle += italic;
  1401.         if (fFontStyle & FW_kUnderline)
  1402.             fMacFontStyle += underline;
  1403.         if (fFontStyle & FW_kStrikeOut)
  1404.             fMacFontStyle += normal;
  1405.         if (fFontStyle & FW_kOutline)
  1406.             fMacFontStyle += outline;
  1407.         if (fFontStyle & FW_kShadow)
  1408.             fMacFontStyle += shadow;
  1409.         if (fFontStyle & FW_kExtended)
  1410.             fMacFontStyle += extend;
  1411.         if (fFontStyle & FW_kCondensed)
  1412.             fMacFontStyle += condense;
  1413.                     
  1414.         // ----- fMacFontID -----
  1415.         
  1416.         // Special case of System and Application Fonts
  1417.         if (fFontName == FW_kSystemFont)
  1418.             fMacFontID = 0;
  1419.         else if (fFontName == FW_kDefaultFont)
  1420.             fMacFontID = 1;
  1421.         else 
  1422.         {
  1423.             short fontNumber;
  1424.             Str255 pascalFontName;
  1425.             
  1426.             fFontName.ExportPascal(pascalFontName);
  1427.             ::GetFNum(pascalFontName, &fontNumber);
  1428.             fMacFontID = fontNumber;
  1429.             
  1430. /**            if (fontNumber == systemFont)
  1431.             {
  1432.                 // fontNum is set to sysFont if fontName is not found.
  1433.                 // We must check for the special case where the system
  1434.                 // font is indeed being retrieved, by comparing the
  1435.                 // name of the font with that of the system font.    
  1436.                 Str255 sysFontName;
  1437.                 ::GetFontName(systemFont, sysFontName);
  1438.                 if (!::EqualString(pascalFontName, sysFontName, FALSE, FALSE))
  1439.                 {
  1440.         //                // font was not found
  1441.         //                BR_THROW(BR_XFontNameNotFound(fFaceName));
  1442.                 }
  1443.             } **/
  1444.         }
  1445.         fMacValidCache = TRUE;
  1446.     }
  1447. }
  1448.  
  1449. #endif
  1450.  
  1451. //----------------------------------------------------------------------------------------
  1452. //    FW_CPrivFontRep::IsEqual
  1453. //----------------------------------------------------------------------------------------
  1454.  
  1455. FW_Boolean FW_CPrivFontRep::IsEqual(const FW_CPrivFontRep* other) const
  1456. {
  1457.     if (other == this)
  1458.         return TRUE;
  1459.         
  1460.     return
  1461.         fFontStyle == other->fFontStyle &&
  1462.         fFontSize == other->fFontSize &&
  1463.         fFontName == other->fFontName;
  1464. }
  1465.  
  1466.